package common

import "time"

//月份 1,01,Jan,January
//
//日　 2,02,_2
//
//时　 3,03,15,PM,pm,AM,am
//
//分　 4,04
//
//秒　 5,05
//
//年　 06,2006
//
//周几 Mon,Monday
//
//时区时差表示 -07,-0700,Z0700,Z07:00,-07:00,MST
//
//时区字母缩写 MST

const (
	// 时间格式常量表
	DATE_TIME_FORMAT_1 = "2006-01-02 15:04:05"
	DATE_TIME_FORMAT_2 = "20060102150405"
	DATE_TIME_FORMAT_3 = "2006.01.02.15:04:05"
	DATE_FORMAT_1      = "2006-01-02"
	DATE_FORMAT_2      = "20060102"
)

// Timestamp 9位时间戳
func Timestamp() int64 {
	return time.Now().Unix()
}

// TimestampFull 13 位毫秒
func TimestampFull() int64 {
	return time.Now().UnixMilli()
}

// FormatTime 格式化
func FormatTime(theTime time.Time, format string) string {
	return theTime.Format(format)
}

// GetNowStr 获取格式化
func GetNowStr(format string) string {
	return time.Now().Format(format)
}

// FormatTimeFromString 将字符串格式化为时间
func FormatTimeFromString(timeStr, format string) (time.Time, error) {
	return time.Parse(format, timeStr)
}

// Today 今天
func Today() string {
	return time.Now().Format(DATE_FORMAT_1)
}

// TodayFormat 根据日期格式格式今天
func TodayFormat(format string) string {
	return time.Now().Format(format)
}

// FirstDayOfMonth 获取本月第一天
func FirstDayOfMonth(theTime time.Time) (firstDay time.Time) {
	return time.Date(theTime.Year(), theTime.Month(), 1, 0, 0, 0, 0, theTime.Location())
}

// LastDayOfMonth 获取本月最后一天
func LastDayOfMonth(theTime time.Time) (lastDay time.Time) {
	return time.Date(theTime.Year(), theTime.Month(), 1, 0, 0, 0, 0, theTime.Location()).AddDate(0, 1, -1)
}

// FirstDayOfYear 获取时间所在年的第一天
func FirstDayOfYear(theTime time.Time) (firstDay time.Time) {
	return time.Date(theTime.Year(), time.January, 1, 0, 0, 0, 0, theTime.Location())
}

// LastDayOfYear 获取时间所在年的最后一天
func LastDayOfYear(theTime time.Time) (lastDay time.Time) {
	return time.Date(theTime.Year(), time.January, 1, 0, 0, 0, 0, theTime.Location()).AddDate(1, 0, -1)
}
